package edu.washington.cs.workflow.recommender;

import java.util.List;
import java.util.Set;

import junit.framework.TestCase;

public class TestParsingTraceFileFreemind extends TestCase {

	public void testFileExportHtml() {
		String file = "./tests/files/freemind_file_export_html_new_version.txt";
		EventTraceProcessor processor = new EventTraceProcessor(file);
		String methodDesc = "freemind.modes.mindmapmode.MindMapController$ExportToHTMLAction.actionPerformed(Ljava/awt/event/ActionEvent;)V";
		List<String> list = processor.getTriggeringActionDescs(methodDesc);
		System.out.println(list);
	}
	
	public void testToggleFolded() {
		String file = "./tests/files/freemind_toggle_folded_new_version.txt";
		EventTraceProcessor processor = new EventTraceProcessor(file);
		String methodDesc = "freemind.modes.actions.ToggleFoldedAction.toggleFolded()V";
		List<String> list = processor.getTriggeringActionDescs(methodDesc);
		System.out.println(list);
	}
	
	public void testBranchAsHtml() {
		String file = "./tests/files/freemind_branch_as_html_new_version.txt";
		EventTraceProcessor processor = new EventTraceProcessor(file);
		String methodDesc = "freemind.modes.mindmapmode.MindMapController$ExportBranchToHTMLAction.actionPerformed(Ljava/awt/event/ActionEvent;)V";
		List<String> list = processor.getTriggeringActionDescs(methodDesc);
		System.out.println(list);
	}
	
	public void testNextFile() {
		String file = "./tests/files/freemind_next_file_new_version.txt";
		EventTraceProcessor processor = new EventTraceProcessor(file);
		String methodDesc = "freemind.controller.MapModuleManager.nextMapModule()V";
		List<String> list = processor.getTriggeringActionDescs(methodDesc);
		System.out.println(list);
	}
	
	//Go to experiments/freemind-0.71
	//java -cp ./freemind-0.71-instr.jar;../../bin;../../libs/simmetrics_jar.jar freemind.main.FreeMind
	public void testFreemind_exportAsHtml() {
		String file = "./tests/demo-traces/freemind-export-as-html-old-version.txt";
		EventTraceProcessor oldProcessor = new EventTraceProcessor(file);
		
		String newFile = "./tests/files/freemind_file_export_html_new_version.txt";
		EventTraceProcessor newProcessor = new EventTraceProcessor(newFile);
		
		this.showInvokedHandlerAndActions(oldProcessor, newProcessor);
	}
	
	public void testFreemind_export_branch_AsHtml() {
		String file = "./tests/demo-traces/freemind-export-branch-as-html-old-version.txt";
		EventTraceProcessor oldProcessor = new EventTraceProcessor(file);
		
		String newFile = "./tests/files/freemind_branch_as_html_new_version.txt";
		EventTraceProcessor newProcessor = new EventTraceProcessor(newFile);
		
		this.showInvokedHandlerAndActions(oldProcessor, newProcessor);
	}
	
	public void testFreemind_prev_next_map() {
		String file = "./tests/demo-traces/freemind-prev-next-map-old-version.txt";
		EventTraceProcessor oldProcessor = new EventTraceProcessor(file);
		
		String newFile = "./tests/files/freemind_next_file_new_version.txt";
		EventTraceProcessor newProcessor = new EventTraceProcessor(newFile);
		
		this.showInvokedHandlerAndActions(oldProcessor, newProcessor);
	}
	
	public void testFreemind_toggle_folded() {
		String file = "./tests/demo-traces/freemind-toggled-folded-old-version.txt";
		EventTraceProcessor oldProcessor = new EventTraceProcessor(file);
		
		String newFile = "./tests/files/freemind_toggle_folded_new_version.txt";
		EventTraceProcessor newProcessor = new EventTraceProcessor(newFile);
		
		this.showInvokedHandlerAndActions(oldProcessor, newProcessor);
	}
	
	private void showInvokedHandlerAndActions(EventTraceProcessor oldProcessor, EventTraceProcessor newProcessor) {
		List<String> handlerDescs = oldProcessor.getAllUniqueActionHandlerDescs();
		for(String desc : handlerDescs) {
			System.out.println("-- handler : " + desc);
			System.out.println("      actions: " + newProcessor.getTriggeringActionDescs(desc));
			System.out.println("its invoked method: ");
			List<String> methods = oldProcessor.getInvokedMethodsByHandler(desc);
			for(String m : methods) {
				System.out.println("   " + m);
				//then query the 
				List<String> descs = newProcessor.getTriggeringActionDescs(m);
				System.out.println("      actions: " + descs);
				
			}
		}
	}
}